<!--  -->
<template>
  <div>
    <van-nav-bar title="账号登录"  left-arrow></van-nav-bar>
    <van-form @submit="onSubmit">
  <van-field
    v-model="formLogin.username"
    placeholder="请输入用户名"

  />
  <van-field
    v-model="formLogin.password"
    type="password"
    placeholder="请输入密码"

  />
  <div style="margin: 16px;">
    <van-button square block type="primary"
    native-type="submit"
    :disabled="isLoding"
    :loading="isLoding"
    >提交</van-button>
  </div>
  <a href="#">还没有账号？去注册</a>
</van-form>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { Notify } from 'vant'
export default {
  name: 'login',
  data () {
    return {
      isLoding: false,
      formLogin: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    ...mapActions(['loginAction']),
    async onSubmit () {
      this.isLoding = true
      try {
        await this.loginAction(this.formLogin)
        Notify({ type: 'success', message: '登录成功' })
        this.isLoding = false
        this.$router.replace('/layout')
      } catch (err) {
        Notify({ type: 'warning', message: '手机号或密码错误' })
        this.isLoding = false
      }
    }
  }
}

</script>
<style lang='less' scoped>
// .van-nav-bar{
//   background-color: #007bff;
// }
</style>
